package
{
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.net.SharedObject;

	public class ActionBarManager
	{
		private var m_actionBar:ActionBar = new ActionBar();
		public function ActionBarManager()
		{
			m_actionBar.addButton(new ActionBarButton('reset')).getDisplay().addEventListener(MouseEvent.CLICK, onReset);
			m_actionBar.addButton(new ActionBarButton('save')).getDisplay().addEventListener(MouseEvent.CLICK, onSave);
			m_actionBar.addButton(new ActionBarButton('buy store')).getDisplay().addEventListener(MouseEvent.CLICK, onBuyStore);
			m_actionBar.addButton(new ActionBarButton('buy citizen')).getDisplay().addEventListener(MouseEvent.CLICK, onBuyCitizen);
			m_actionBar.addButton(new ActionBarButton('cancel')).getDisplay().addEventListener(MouseEvent.CLICK, onCancel);
			m_actionBar.addButton(new ActionBarButton('draw paths')).getDisplay().addEventListener(MouseEvent.CLICK, onDrawPath);
			m_actionBar.addButton(new ActionBarButton('buy road')).getDisplay().addEventListener(MouseEvent.CLICK, onBuyRoad);
		}

		private function onReset(me:MouseEvent):void{
			var so:SharedObject = SharedObject.getLocal("Game");
			so.data.player = null;
		}		
		
		private function onSave(me:MouseEvent):void{
			var so:SharedObject = SharedObject.getLocal("Game");
			so.data.player = Global.player.serialize();
		}

		private function onBuyRoad(me:MouseEvent):void{
			Global.inputManager.addGameMode(new GMBuy(Road.createRoad(), Global.isoScene));
		}		
		
		private function onBuyStore(me:MouseEvent):void{
			//Global.player.doAction("buyStore");
			Global.inputManager.addGameMode(new GMBuy(Store.createStore(), Global.isoScene));
		}
		
		private function onBuyCitizen(me:MouseEvent):void{
			var citizen:Citizen = new Citizen();
			Global.player.buyCitizen(citizen);
		}
		
		private function onCancel(me:MouseEvent):void{
			Global.inputManager.popGameMode();
		}
		
		private function onDrawPath(me:MouseEvent):void{
			Global.pathManager.showDebugRendering();
			Global.inputManager.addGameMode(new GMDrawPath());
		}
		
		public function getActionBarDisplay():Sprite{
			return m_actionBar.getDisplay();
		}
	}
}